<template>
  <div>

    <FormPanel ref="formPanel" :list="formList" :cols="3" :labelWidth="110" :isSubmitBtn="false"/>
    <!-- <el-col :span="24" class="bg2">
      <BreakSpace
        :labelStyle="{fontSize:'12px'}"
        :containerStyle="{ marginBottom: '0px' }"></BreakSpace>
      <FilterTable
        ref="tableZCheng"
        selectionType="single"
        :isSelectColumn="false"
        :columns="columns"
        :isMemoryPagination="true"
        height="200"
        columnsRef="glqcduanzongchengPjxmTable"
        :isColumnFilter="true"
        :onColumnsChange="columns => (this.columns = columns)"
        :onRowSelectChange="arr => (this.onChangeColumn = arr)"
      >
      </FilterTable>
    </el-col> -->

    <el-col :span="24" class="bg2" >
      <!-- <BreakSpace
        :labelStyle="{fontSize:'12px',paddingLeft:'10px'}"
        :containerStyle="{ marginBottom: '0px'}"></BreakSpace> -->
      <div class="table-title">累计维修天数&nbsp;{{paraTypePart}}&nbsp;</div>
      <!-- <div class="table-title">累计维修天数</div> -->
      <FilterTable
        ref="tableVin"
        :summary-method="getSummaries"
        selectionType="single"
        :isSelectColumn="false"
        :columns="columns2"
        height="auto"
        :isMemoryPagination="true"
        :isColumnFilter="true"
        :onColumnsChange="columns => (this.columns2 = columns)"
        :onRowSelectChange="arr => (this.onChangeColumn = arr)"
      >
      </FilterTable>
    </el-col>

    <div v-for="(k,v) in vinPartDTOList">
      <el-col :span="24" class="bg2">
        <!-- <BreakSpace
          :labelStyle="{fontSize:'12px'}"
          :containerStyle="{ marginBottom: '0px' }"></BreakSpace> -->
        <div class="table-title">&nbsp;{{v}}&nbsp;</div>
        <FilterTable
          ref="tablePeij"
          selectionType="single"
          :dataSource ='k'
          :isSelectColumn="false"
          :columns="columns3"
          :isMemoryPagination="true"
          height="auto"
          :isColumnFilter="true"
          :onColumnsChange="columns => (this.columns3 = columns)"
          :onRowSelectChange="arr => (this.onChangeColumn = arr)"
        >
        </FilterTable>
      </el-col>
    </div>

    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="closeMenu('2')">关闭
      </el-button>
    </div>
  </div>
</template>

<script>
import {getParaItem,getParaItemByVinAndDealerCode} from '@/api/repair/threePacksOfManager/warningQueryCDuan';

import {dictionary} from '@/utils/dictMixin';
import {isEmpty} from '@/utils/utils';
import {exportExcelFile} from '@/utils/index';

export default {
  name: 'detail',
  mixins: [dictionary],
  props: ['handleType', 'vinId','rowData'],
  data()
  {
    this.saveData = null;
    return {

      formList: this.createFormList(),
      columns: this.createTableColumns(),
      columns2: this.createTableColumns2(),
      columns3: this.createTableColumns3(),
      detailObj: {},
      vinPartDTOList : [],
      paraTypePart:'',
    };
  },
  components: {},
  mounted()
  {
    //this.BaseTableZCengTable = this.$refs.tableZCheng.$refs.pageTable;
    this.BaseSportVin = this.$refs.tableVin.$refs.pageTable;
    this.BasePeijTable = this.$refs.pageTable;
    //this.getData();
    this.getTablesDetail();

  },
  methods: {

    // 根据vin+dealercode查询
    async getTablesDetail(){
      let resData =  await getParaItemByVinAndDealerCode({'vin':this.rowData.vin,'dealerCode':this.rowData.dealerCode});
      if(resData.resultCode == 200 && resData.success == true){
        let data = isEmpty(resData['data']) ? {} : resData['data'];
        let threeRepairInfoDtos = isEmpty(data['threeRepairInfoDtos']) ? [] : data['threeRepairInfoDtos'];
        let vinPartDTOS = isEmpty(data['vinPartDTOS']) ? [] : data['vinPartDTOS'];
        this.BaseSportVin.EXECUTE_INSERT(threeRepairInfoDtos);
        //this.BasePeijTable.EXECUTE_INSERT(vinPartDTOS);
        this.paraTypePart = data.paraTypePart;

        let vinPartDTOList = isEmpty(data['vinPartDTOList']) ? [] : data['vinPartDTOList'];
        this.vinPartDTOList = vinPartDTOList;



        for (let i in data)
        {
          this.formList.map(x =>
          {
            if (i == x.fieldName)
            {
              x.initialValue = data[i];
            }
          });
        }
      }
    },

    getSummaries(param) {
      const { columns2, data } = param;
      const sums = [];
      columns2.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总价';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ' 元';
        } else {
          sums[index] = 'N/A';
        }
      });

      return sums;
    },

    /*根据ID查询*/
    async getData()
    {
      console.log(JSON.stringify(this.rowData)+"--------------------this.rowData")
      let res = await getParaItem({'id': this.vinId});

      if (res.resultCode == 200 && res.success == true)
      {
        let data = isEmpty(res['data']) ? {} : res['data'];

        let vinPartDTOS = isEmpty(data['vinPartDTOS']) ? [] : data['vinPartDTOS'];

        let vinAssemblyDTOS = isEmpty(data['vinAssemblyDTOS']) ? [] : data['vinAssemblyDTOS'];

        this.BaseTableZCengTable.EXECUTE_INSERT(vinAssemblyDTOS);

        this.BasePeijTable.EXECUTE_INSERT(vinPartDTOS);


        let vinParams = {
          license: isEmpty(data['license']) ? '' : data['license'],
          vin: isEmpty(data['vin']) ? '' : data['vin'],
          totalRepairTime: isEmpty(data['totalRepairTime']) ? '' : (parseFloat(data['totalRepairTime']) / 24)
        }

        this.BaseSportVin.EXECUTE_INSERT([vinParams]);


        for (let i in data)
        {
          this.formList.map(x =>
          {
            if (i == x.fieldName)
            {
              x.initialValue = data[i];
            }
          });
        }
      }

    },
    async closeMenu(type)
    {
      this.$emit('close')
    },
    createTableColumns()
    {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          fixed: 'left',
          render: props =>
          {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '总成代码',
          dataIndex: 'assemblyCode',
          width: 150,
          sorter: true

        },
        {
          title: '总成名称',
          dataIndex: 'assemblyName',
          width: 150,
          sorter: true

        },
        {
          title: '当前次数',
          dataIndex: 'repairCount',
          width: 150,
          sorter: true
        },

        {
          title: '法定次数',
          dataIndex: 'legalCount',
          sorter: true
        },
      ];
    },

    createTableColumns2()
    {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          fixed: 'left',
          render: props =>
          {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '车牌号',
        //   dataIndex: 'license',
        //   width: 150,
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',

        // },
        {
          title: 'VIN',
          dataIndex: 'vin',
          width: 150,
          sorter: true

        },
        {
          title: '服务中心代码',
          dataIndex: 'dealerCode',
          width: 150,
          sorter: true
        },
        {
          title: '服务中心名称',
          dataIndex: 'dealerName',
          width: 150,
          sorter: true
        },
        {
          title: '工单号',
          dataIndex: 'roNo',
          width: 150,
          sorter: true
        },
        {
          title: '结算日期',
          dataIndex: 'balanceTime',
          width: 150,
          sorter: true

        },
        {
          title: '维修开单日期',
          dataIndex: 'roCreateDate',
          width: 150,
          sorter: true

        },
        {
          title: '维修竣工日期',
          dataIndex: 'completeTime',
          width: 150,
          sorter: true

        },
        {
          title: '行驶里程',
          dataIndex: 'totalChangeMileage',
          width: 150,
          sorter: true

        },
        {
          title: '本次维修天数',
          dataIndex: 'thisRepairDays',
          width: 150,
          sorter: true,
          summation: true
          // filter: true,
          // filterType: 'input',
        }
        // {
        //   title: '法定天数',
        //   dataIndex: 'remarks',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        // },
      ];
    },
    createTableColumns3()
    {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          fixed: 'left',
          render: props =>
          {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '备件代码',
          dataIndex: 'partNo',
          width: 150,
          sorter: true
        },
        {
          title: '备件名称',
          dataIndex: 'partName',
          width: 150,
          sorter: true

        },
        {
          title: '当前次数',
          dataIndex: 'repairCount',
          width: 150,
          sorter: true,
          summation: true

        },

        {
          title: '法定次数',
          dataIndex: 'legalCount',
          sorter: true
        },
      ];
    },
    createFormList()
    {

      return [
        {
          type: 'BREAK_SPACE',
          label: '客户三包信息',
        },

        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          itemList: [],
          disabled: true,
          placeholder: '',
          // rules: [{required: true, trigger: 'change'}],
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          disabled: true,

          placeholder: '请输入',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName',
          placeholder: '',
          disabled: true,

          initialValue: '',

        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'mileage',
          placeholder: '请选择',
          disabled: true,

          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '累计维修时间',
          fieldName: 'repairDaySum',
          placeholder: '请选择',
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '发动机号',
          fieldName: 'engineNo',
          placeholder: '请选择',
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'model',
          placeholder: '请选择',
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '购车日期',
          fieldName: 'salesDate',
          placeholder: '请选择',
          disabled: true,
          initialValue: '',
        },
        // {
        //   type: 'INPUT',
        //   label: '联系人',
        //   fieldName: 'linkName',
        //   placeholder: '请选择',
        //   disabled: true,
        //   initialValue: '',
        // },
        // {
        //   type: 'INPUT',
        //   label: '邮编',
        //   fieldName: 'counts3',
        //   placeholder: '请选择',
        //   disabled: true,
        //   rules: [{required: false, trigger: 'change'}],
        //   initialValue: '',
        // },
        // {
        //   type: 'INPUT',
        //   label: '联系电话',
        //   fieldName: 'linkTel',
        //   placeholder: '请选择',
        //   disabled: true,
        //   rules: [{required: false, trigger: 'change'}],
        //   initialValue: '',
        // },

      ];
    },
  }
};
</script>

<style scoped lang="less">
.bg1 {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  padding-left: 0;
  padding-top: 15px;
  padding-bottom: 15px;
}

.bg2 {
  margin-top: 10px;
  margin-bottom: 10px;
}

.btn {
  text-align: center;
}

.btnStyle {
  margin-top: 10px;
}
</style>
